package com.jacky.javafx.enums;

import java.util.Arrays;
import java.util.Optional;

public enum AppUserStateEnum {

    NORMAL("NORMAL", "正常"),
    FREEZE("FREEZE", "冻结"),
    DISABLE("DISABLE", "禁用"),
    UN_KNOW("UNKNOW", "未知");
    private final String code;
    private final String zh;

    AppUserStateEnum(String code, String zh) {
        this.code = code;
        this.zh = zh;
    }

    public static AppUserStateEnum findByCode(String code) {
        Optional<AppUserStateEnum> match = Arrays.stream(AppUserStateEnum.values()).filter(e -> e.code.equals(code)).findFirst();
        return match.orElse(UN_KNOW);
    }

    public static AppUserStateEnum findByZh(String zh) {
        Optional<AppUserStateEnum> match = Arrays.stream(AppUserStateEnum.values()).filter(e -> e.zh.equals(zh)).findFirst();
        return match.orElse(UN_KNOW);
    }

    public String code() {
        return code;
    }

    public String zh() {
        return zh;
    }
}
